package games.tetris;

import graphics.Sprite2D;
import hardware.Display2D;

public class Brick extends Sprite2D{

	public static final int BRICK_TYPE_NONE = 0;
	public static final int BRICK_TYPE_I 	= BRICK_TYPE_NONE+1;	
	public static final int BRICK_TYPE_L 	= BRICK_TYPE_I+1;
	public static final int BRICK_TYPE_S 	= BRICK_TYPE_L+1;
	public static final int BRICK_TYPE_Z 	= BRICK_TYPE_S+1;
	public static final int BRICK_TYPE_T 	= BRICK_TYPE_Z+1;
	
	public static final int ORIENTATION_0	= 0;
	public static final int ORIENTATION_90	= 1;
	public static final int ORIENTATION_180	= 2;
	public static final int ORIENTATION_270	= 3;

	
	private static final short BRICK_COLOR_I	= 0x0F0;
	private static final short BRICK_COLOR_L	= 0x00F;
	private static final short BRICK_COLOR_S	= 0xF00;
	private static final short BRICK_COLOR_Z	= 0x707;
	private static final short BRICK_COLOR_T	= 0x555;
	
	
	
private int brickType=BRICK_TYPE_NONE;
private int brickOrientation=ORIENTATION_0;

public void draw()
{
	
	switch(brickType)
		{
		case BRICK_TYPE_I:
				drawIBrick();
			break;
			
		case BRICK_TYPE_L:
			drawLBrick();
		break;		
			
		
		case BRICK_TYPE_S:
			drawSBrick();
		break;
		
		case BRICK_TYPE_Z:
			drawZBrick();
		break;
		
		case BRICK_TYPE_T:
			drawTBrick();
		break;
		
		
		}
	
	
}


private void drawIBrick()
{
	switch (brickOrientation)
		{
		case ORIENTATION_0:
		case ORIENTATION_180:
			Display2D.setPixel(xPos, yPos-1, 	BRICK_COLOR_I);
			Display2D.setPixel(xPos, yPos, 		BRICK_COLOR_I);
			Display2D.setPixel(xPos, yPos+1, 	BRICK_COLOR_I);
			break;

		case ORIENTATION_90:
		case ORIENTATION_270:
			Display2D.setPixel(xPos-1, 	yPos, BRICK_COLOR_I);
			Display2D.setPixel(xPos, 	yPos, BRICK_COLOR_I);
			Display2D.setPixel(xPos+1, 	yPos, BRICK_COLOR_I);
			
			break;	
			
		}
	
}


private void drawLBrick()
{
	switch (brickOrientation)
	{
	case ORIENTATION_0:
		Display2D.setPixel(xPos, 	yPos, 	BRICK_COLOR_S);
		Display2D.setPixel(xPos, 	yPos-1, BRICK_COLOR_S);
		Display2D.setPixel(xPos, 	yPos+1, BRICK_COLOR_S);
		Display2D.setPixel(xPos+1, 	yPos-1, BRICK_COLOR_S);
		break;
		
	case ORIENTATION_90:
		
		break;

	case ORIENTATION_180:
		
		break;
	case ORIENTATION_270:
		
		break;	
		
	}	
}


private void drawSBrick()
{
	switch (brickOrientation)
	{
	case ORIENTATION_0:
	case ORIENTATION_180:
		Display2D.setPixel(xPos, 	yPos, 	BRICK_COLOR_S);
		Display2D.setPixel(xPos+1, 	yPos, 	BRICK_COLOR_S);
		Display2D.setPixel(xPos, 	yPos+1, BRICK_COLOR_S);
		Display2D.setPixel(xPos-1, 	yPos+1, BRICK_COLOR_S);
		break;

	case ORIENTATION_90:
	case ORIENTATION_270:
		Display2D.setPixel(xPos, 	yPos, 	BRICK_COLOR_S);
		Display2D.setPixel(xPos, 	yPos+1, BRICK_COLOR_S);
		Display2D.setPixel(xPos+1, 	yPos, 	BRICK_COLOR_S);
		Display2D.setPixel(xPos+1, 	yPos+1, BRICK_COLOR_S);		
		break;	
		
	}	
}


private void drawZBrick()
{
	switch (brickOrientation)
	{
	case ORIENTATION_0:
	case ORIENTATION_180:
		Display2D.setPixel(xPos, 	yPos, 	BRICK_COLOR_Z);
		Display2D.setPixel(xPos-1, 	yPos, 	BRICK_COLOR_Z);
		Display2D.setPixel(xPos, 	yPos+1, BRICK_COLOR_Z);
		Display2D.setPixel(xPos+1, 	yPos+1, BRICK_COLOR_Z);
		break;

	case ORIENTATION_90:
	case ORIENTATION_270:
		Display2D.setPixel(xPos, 	yPos, 	BRICK_COLOR_Z);
		Display2D.setPixel(xPos, 	yPos+1, BRICK_COLOR_Z);
		Display2D.setPixel(xPos-1, 	yPos, 	BRICK_COLOR_Z);
		Display2D.setPixel(xPos-1, 	yPos+1, BRICK_COLOR_Z);		
		break;	
		
	}	
}

private void drawTBrick()
{
	switch (brickOrientation)
	{
	case ORIENTATION_0:
		Display2D.setPixel(xPos, 	yPos, 	BRICK_COLOR_T);
		Display2D.setPixel(xPos-1, 	yPos+1, BRICK_COLOR_T);
		Display2D.setPixel(xPos, 	yPos+1, BRICK_COLOR_T);
		Display2D.setPixel(xPos+1, 	yPos+1,	BRICK_COLOR_T);
		break;
		
	case ORIENTATION_90:
		Display2D.setPixel(xPos, 	yPos, 	BRICK_COLOR_T);
		Display2D.setPixel(xPos+1, 	yPos+1, BRICK_COLOR_T);
		Display2D.setPixel(xPos+1, 	yPos, 	BRICK_COLOR_T);
		Display2D.setPixel(xPos+1, 	yPos-1, BRICK_COLOR_T);
		break;

	case ORIENTATION_180:
		Display2D.setPixel(xPos, 	yPos+1, BRICK_COLOR_T);
		Display2D.setPixel(xPos-1, 	yPos, 	BRICK_COLOR_T);
		Display2D.setPixel(xPos, 	yPos, 	BRICK_COLOR_T);
		Display2D.setPixel(xPos+1, 	yPos,	BRICK_COLOR_T);
		break;
		
	case ORIENTATION_270:
		Display2D.setPixel(xPos, 	yPos, 	BRICK_COLOR_T);
		Display2D.setPixel(xPos-1, 	yPos+1, BRICK_COLOR_T);
		Display2D.setPixel(xPos-1, 	yPos, 	BRICK_COLOR_T);
		Display2D.setPixel(xPos-1, 	yPos-1, BRICK_COLOR_T);	
		break;	
		
	}		
}

}